package com.example.demo.pojo.entity;

import com.example.demo.controller.ValidateGroup;
import com.example.demo.enumeration.Campus;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.validator.constraints.Length;

import java.time.LocalDateTime;

@Getter
@Setter
@ToString
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public class User {
    private Long id;

    @NotBlank(groups = ValidateGroup.Login.class, message = "手机号码不能为空")
    @Pattern(regexp = "^1[0-9]{10}$", message = "手机号码格式错误")
    private String phone;

    @NotBlank(groups = ValidateGroup.Crud.Update.class, message = "用户名不能为空")
    @Length(min = 1, max = 20, message = "名称长度限定为1-20个字符")
    private String name;

    @NotBlank(groups = ValidateGroup.Login.class, message = "密码不能为空")
    @Length(min = 6, max = 20, message = "密码长度限定为6-20个字符")
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    private String password;

    private String studentId;

    @NotNull(groups = ValidateGroup.Crud.Update.class, message = "校区不能为空")
    private Campus campus;

    private String picture;

    private Integer credit;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;

    public User() {
    }

    public User(Long id, String phone, String name, String password, String studentId, Campus campus, String picture, Integer credit, LocalDateTime createTime, LocalDateTime updateTime) {
        this.id = id;
        this.phone = phone;
        this.name = name;
        this.password = password;
        this.studentId = studentId;
        this.campus = campus;
        this.picture = picture;
        this.credit = credit;
        this.createTime = createTime;
        this.updateTime = updateTime;
    }
}
